package in.muton.panels.paginator.badgehelpers.course;

import in.muton.edushare.EduShareSession;
import in.muton.edushare.auth.roles.UnivRoleCheck;
import in.muton.edushare.processing.objects.DeptDataHandler;
import in.muton.panels.paginator.helpers.BadgeInterface;

import org.apache.wicket.model.IModel;

import com.edushare.common.dao.DepartmentsDAO;
import com.edushare.common.dao.PollStatsDAO;
import com.edushare.common.vo.Departments;
import com.edushare.common.vo.Universities;
import com.edushare.common.vo.Users;

public class DeptBadgeInterface implements BadgeInterface {

	public DeptBadgeInterface(IModel<Universities> univModel){
		this.univModel = univModel;
	}
	
	
	public String removeDept(IModel<Departments> dept) {
		DeptDataHandler ddh = new DeptDataHandler(dept);
		PollStatsDAO psdao = new PollStatsDAO(EduShareSession.get().getSessionORMInterface());
		if(ddh.getCourses().getObject().size()!=0)
			return "Cannot delete department as it contains courses.<br/>"+
				"Please remove courses for this department before proceeding.";
		if(ddh.getPeople().getObject().size()!=0)
			return "Cannot remove department as people are added to it.<br/>"+
				"Please remove all people from this department before proceeding.";
		if(psdao.getTotalPolls(dept.getObject())!=0)
			return "Cannot remove department as it has polls.<br/>"+
				"Please remove all polls from this department before proceeding.";
		if(dept.getObject().getCurriculums().size()>0)
			return "Cannot remove department as this department has running academic programs<br/>."+
				"Please delete the academic programs before proceeding";
		
		
		new DepartmentsDAO(EduShareSession.get().getSessionORMInterface()).
			removeDept(dept.getObject(), univModel.getObject());
		
		return "Removed department "+ dept.getObject().getDeptName()+" from "+
			univModel.getObject().getUniversityName()+".";
	}
	
	
	public boolean isAdmin() {
		Users user = EduShareSession.get().getLoggedInUser();
		if (univModel != null)
			return new UnivRoleCheck(univModel.getObject(), user).isAdmin();
		return false;
	}

	private IModel<Universities> univModel = null;
	private static final long serialVersionUID = -8304519209146414696L;
}
